package com.ncloud.crm.mapper;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.crm.entity.Logistics;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by shiqiang on 2017/7/5.
 */
@Mapper
public interface LogisticsInfoMapper {
    @Insert("insert into bs_o_node_logistics(logistics_id, work_id, node_id,company_id, company, out_logistics_id,create_time)"
            + " values(#{logisticsId}, #{workId}, #{nodeId}, #{companyId},#{company}, #{outLogisticsId},#{createTime})")
    public int insertLogistics(Logistics logistics);

    @Select(value = { "select * from bs_o_node_logistics a "
            + " where a.work_id = #{workId} and a.node_id = #{nodeId}  order by a.create_time desc limit 1" })
    @Results({ @Result(column = "logistics_id", property = "logisticsId"),
            @Result(column = "work_id", property = "workId"),
            @Result(column = "node_id", property = "nodeId"),
            @Result(column = "company_id", property = "companyId"),
            @Result(column = "company", property = "company"),
            @Result(column = "out_logistics_id", property = "outLogisticsId"),
            @Result(column = "create_time", property = "createTime")
    })
    public Logistics getLogistics(@Param("workId") Long workId, @Param("nodeId") Long nodeId);

    @Select(value = { "select a.work_id,a.node_id,a.order_id,a.node_name,b.prod_name,c.cust_id,c.cust_name,c.contact_email,c.contact_name  from bs_o_node a ,bs_o_product b ,bs_o_cust c "
            + " where a.order_id=b.order_id and a.order_id=c.order_id and a.node_id =#{nodeId} and a.work_id = #{workId} limit 1" })
    @Results({ @Result(column = "work_id", property = "workId"),
            @Result(column = "node_id", property = "nodeId"),
            @Result(column = "order_id", property = "orderId"),
            @Result(column = "node_name", property = "nodeName"),
            @Result(column = "prod_name", property = "prodName"),
            @Result(column = "cust_id", property = "custId"),
            @Result(column = "cust_name", property = "custName"),
            @Result(column = "contact_email", property = "contactEmail"),
            @Result(column = "contact_name", property = "contactName")
    })
    public JSONObject getLogisticsMailInfo(@Param("workId") Long workId, @Param("nodeId") Long nodeId);
}
